<template>
  <view class="container">
    <el-button type="primary" @click="takePhoto">拍照上传</el-button>
  </view>
</template>

<script>
export default {
  methods: {
    takePhoto() {
      const that = this;
      uni.chooseImage({
        count: 1,
        sourceType: ['camera'], // 只允许拍照
        success(res) {
          const tempFilePath = res.tempFilePaths[0];
          // 模拟上传成功，将图片路径存储到本地存储
          uni.setStorageSync('imageSrc', tempFilePath);
          // 跳转到显示溯源信息的页面
          uni.navigateTo({
            url: '/pages/scan/trace'
          });
        },
        fail(err) {
          console.error('选择图片失败：', err);
          that.$message.error('选择图片失败');
        }
      });
    }
  }
};
</script>

<style scoped>
.container {
  display: flex;
  justify-content: center;
  margin-top: 20px;
}
</style>